package day06;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
public class Practice02 {
    public static void main(String[] args) {
        //1. 猜数字
        //2. 生成验证码
        //3. 素数
        //4. 计算机票折后价格
        //5. 计算总分和平均分
        Scanner scan = new Scanner(System.in);
        //1.猜数字
        int numa = (int) (Math.random() * 50 + 1);
        System.out.println("猜数字游戏");
        System.out.println(numa);
        while (true) {
            System.out.println("猜吧");
            int numaa = scan.nextInt();
            if (numaa > numa) {
                System.out.println("猜大了点");
            } else if (numaa < numa) {
                System.out.println("猜大了点");
            } else {
                System.out.println("猜对了");
                break;
            }
        }
        //2.验证码
        String vCode1 = vCode(5);
        System.out.println(vCode1);
        //3.素数
        for(int c =2;c<=200;c++){
            boolean flag1 = true;
            for(int d =2;d<=c/2;d++){
                if(c%d==0){
                    flag1=false;
                    break;
                }
            }
            if(flag1){
                System.out.print(c+"是素数"+"\t");
            }
            System.out.println();
        }
        //4.飞机票
        System.out.println("请输入原价：");
        double pr01 = scan.nextDouble();
        System.out.println("请选择档次：1.一等座 2.二等座 3.三等座");
        int lv = scan.nextInt();
        System.out.println("请选择起始时刻：");
        int time = scan.nextInt();
        double finalPrice = toP(pr01,lv,time);
        System.out.println("最终价为："+finalPrice);
        //5.计算总分和平均分
        double[] ee = new double[7];
        for(int e =1;e<=7;e++){
            System.out.println("请"+e+"号评委打分");
            ee[e-1]= scan.nextDouble();
        }
        double toS2 = toS(ee);
        double avgS2 = avgS(ee);
        System.out.println("总分："+toS2);
        System.out.println("平均分："+avgS2);


    }
    //验证码
    public static String vCode(int length){
        String aa ="";
        Random rand= new Random();
        char[]bb ={  'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'
                , 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G'
                , 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',
                'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
        for(int a =0;a<length;a++){
            int b = rand.nextInt(bb.length);
            aa =aa+bb[b];
        }
        return aa;
    }
    //飞机票
    public static double toP(double pr,int lv,int time){
        switch (lv) {
            case 1:
                if (time >= 8 && time <= 22) {
                    pr = pr * 0.95;
                } else {
                    pr = pr * 0.9;
                }
                break;
            case 2:
                if (time >= 8 && time <= 22) {
                    pr = pr * 0.85;
                } else {
                    pr = pr * 0.8;
                }break;
            case 3:
                if (time >= 8 && time <= 22) {
                    pr = pr * 0.75;
                } else {
                    pr = pr * 0.7;
                }break;
        }
        return pr;
    }
    //总分，平均分
    public static double toS(double[]ee){
        double ff=0;
        for (int f =0;f<ee.length;f++){
             ff += ee[f];
        }
        double maxEe=ee[0];
        double minEe=ee[0];
        for (int g =1;g<ee.length;g++){
            if (ee[g]>maxEe){
                maxEe=ee[g];
            }
            if (ee[g]<minEe){
                minEe=ee[g];
            }
        }
        ff=ff-maxEe-minEe;
        return ff;
    }
    public static double avgS(double[]ee){
        double toS1 =toS(ee);
        double avgS1 = toS1/(ee.length-2);
        return avgS1;
    }

}
